package o;

import android.content.Context;
import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import o.bjl.d;
import o.fus.a;

public class bjw {
    public static <T extends bje> void ˏ(Context context, fuv o_fuv, bjl o_bjl, final bjf<T> o_bjf_T) {
        final bjk o_bjk = new bjk();
        if (!bju.ॱ(context)) {
            ˏ(o_bjk, bju.ˊ(o_bjf_T.getClass()), 0, false, null);
            o_bjf_T.ˋ(o_bjk);
        }
        File file = new File(o_bjl.ˎ());
        if (!file.exists()) {
            o_bjk.ˏ(false);
            o_bjk.ˏ(-1);
            o_bjk.ˋ(new FileNotFoundException("cannot find upload file:" + file.getAbsolutePath()));
            o_bjf_T.ˋ(o_bjk);
        }
        o_fuv.ˎ(ˏ(new a(), o_bjl.ॱ()).ˎ(o_bjl.ˊ()).ˊ(fuw.create(fup.ॱ(ˎ(o_bjl.ॱ())), file)).ॱ()).enqueue(new fua() {
            public void onFailure(ftz o_ftz, IOException iOException) {
                bjw.ˏ(o_bjk, bju.ˊ(o_bjf_T.getClass()), -2, false, null);
                o_bjf_T.ˋ(o_bjk);
            }

            public void onResponse(ftz o_ftz, fvb o_fvb) {
                o_bjk.ˏ(true);
                o_bjk.ˏ(o_fvb.ˊ());
                try {
                    Object ˏ = bjw.ˋ(bju.ˊ(o_bjf_T.getClass()));
                    if (ˏ instanceof bjr) {
                        ˏ = (bjr) ˏ;
                        ˏ.ˋ(o_fvb.ᐝ().ʽ());
                        o_bjk.ˋ(ˏ);
                    }
                } catch (Exception e) {
                    o_bjk.ˋ(e);
                }
                o_bjf_T.ˋ(o_bjk);
            }
        });
    }

    private static void ˏ(bjk o_bjk, Class cls, int i, boolean z, Exception exception) {
        o_bjk.ˏ(z);
        o_bjk.ˏ(i);
        o_bjk.ˋ(exception);
        o_bjk.ˋ(ˋ(cls));
    }

    private static <T> T ˋ(Class<T> cls) {
        try {
            return cls.newInstance();
        } catch (InstantiationException e) {
            return null;
        } catch (IllegalAccessException e2) {
            return null;
        }
    }

    private static a ˏ(a aVar, List<d> list) {
        if (list != null && list.size() > 0) {
            for (d dVar : list) {
                aVar.ˋ(dVar.ˋ(), dVar.ˏ());
            }
        }
        return aVar;
    }

    private static String ˎ(List<d> list) {
        if (list != null && list.size() > 0) {
            for (d dVar : list) {
                if (HttpContants.KEY_CONTENT_TYPE.equals(dVar.ˋ())) {
                    return dVar.ˏ();
                }
            }
        }
        return "image/jpeg";
    }
}
